package control;

import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import entity.Setting;
import service.SetService;
import service.SetServiceimpl;

public class Setset extends HttpServlet{
	SetService svc=new SetServiceimpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    	// TODO Auto-generated method stub
    	req.setCharacterEncoding("utf-8");
    	String email = null;
		Integer typeid = null;;
		String password = null;
		for(Cookie c:req.getCookies()) {
			if(c.getName().equals("email")) {
				email = c.getValue();
			}
			if(c.getName().equals("typeid")) {
				typeid = Integer.valueOf(c.getValue());
			}
			if(c.getName().equals("password")) {
				password = c.getValue();
			}
		}
		Setting set=null;
		Set<Entry<String, String[]>> entrySet = req.getParameterMap().entrySet();
		for(Entry<String, String[]> e:entrySet) {
			System.out.println(e.getKey()+"  ///   "+e.getValue());
		}
		System.out.println("hhh"+entrySet);
		Integer everynum = Integer.valueOf(req.getParameter("everynum"));
		Integer leastnum = Integer.valueOf(req.getParameter("leastnum"));
		String booktype = req.getParameter("booktype");
		Integer bookpag = Integer.valueOf(req.getParameter("bookpag"));
		Integer sequence = Integer.valueOf(req.getParameter("sequence"));
		Integer istranslate =Integer.valueOf(req.getParameter("istranslate"));
		set=new Setting(email, sequence, everynum, leastnum, istranslate, booktype, bookpag);
		try {
			 svc.updateset(email,set);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(set);
		resp.setCharacterEncoding("Gbk");
		resp.getWriter().print("<script charset=\"utf-8\"> alert(\"修改成功\"); window.history.back(-1);</script>");
    }

}
